package com.hs.mod_syslog.adapter

import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.DiffUtil
import com.hs.framework.base.BaseRecyclerAdapter
import com.hs.framework.enums.SysLogSourceTypeEnum
import com.hs.framework.enums.SysLogStatusEnum
import com.hs.mod_syslog.R
import com.hs.room.model.sys.SysLog

class SysLogListAdapter : BaseRecyclerAdapter<SysLog>() {


    override fun getLayoutResId(): Int {
        return R.layout.sys_log_list_item
    }

    override fun bindData(holder: BaseViewHolder?, data: SysLog?, position: Int) {

        var  logNameTv =   holder?.itemView?.findViewById<TextView>(R.id.logNameTv)
        var  messageTv =   holder?.itemView?.findViewById<TextView>(R.id.messageTv)
        var  sourceTypeTv =   holder?.itemView?.findViewById<TextView>(R.id.sourceTypeTv)
        var  statusTv =   holder?.itemView?.findViewById<TextView>(R.id.statusTv)
        var  createTimeTv =   holder?.itemView?.findViewById<TextView>(R.id.createTimeTv)
        var  createByTv =   holder?.itemView?.findViewById<TextView>(R.id.createByTv)
        var itemRootView = holder?.itemView?.findViewById<LinearLayout>(R.id.itemRootView);

        logNameTv?.setTextColor(holder!!.itemView.context.getColor(com.hs.framework.R.color.base_color666))
        messageTv?.setTextColor(holder!!.itemView.context.getColor(com.hs.framework.R.color.base_color666))
        sourceTypeTv?.setTextColor(holder!!.itemView.context.getColor(com.hs.framework.R.color.base_color666))
        statusTv?.setTextColor(holder!!.itemView.context.getColor(com.hs.framework.R.color.base_color666))
        createTimeTv?.setTextColor(holder!!.itemView.context.getColor(com.hs.framework.R.color.base_color666))
        createByTv?.setTextColor(holder!!.itemView.context.getColor(com.hs.framework.R.color.base_color666))

        if (position % 2 == 0){
            itemRootView!!.setBackgroundColor(holder!!.itemView.context.getColor(com.hs.framework.R.color.base_stripe))
        }else{
            itemRootView!!.setBackgroundColor(holder!!.itemView.context.getColor(com.hs.framework.R.color.white))
        }

        logNameTv?.text = data?.logName
        messageTv?.text = data?.message
        sourceTypeTv?.text = SysLogSourceTypeEnum.fromInt(data!!.sourceType!!)?.description
        statusTv?.text = SysLogStatusEnum.fromInt(data!!.status!!)?.description
        createTimeTv?.text = data?.createTime
        createByTv?.text = data?.createBy


    }
}